﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using System;
using Terraria;
using Terraria.GameContent;
using Terraria.ID;
using Terraria.ModLoader;

namespace MoLingsArmory.Common.Utilies
{
    public static class VisualHelpers
    {
        public static void VanillaSparkleFX(float opacity, SpriteEffects dir, Vector2 drawpos, Color drawColor, Color shineColor, float flareCounter, float fadeInStart, float fadeInEnd, float fadeOutStart, float fadeOutEnd, float rotation, Vector2 scale, Vector2 fatness)
        {
            Texture2D value = TextureAssets.Extra[ExtrasID.SharpTears].Value;
            Color color = shineColor * opacity * 0.5f;
            color.A = 0;
            Vector2 origin = value.Size() / 2f;
            Color color2 = drawColor * 0.5f;
            float lerpScalar = Utils.GetLerpValue(fadeInStart, fadeInEnd, flareCounter, true) * Utils.GetLerpValue(fadeOutEnd, fadeOutStart, flareCounter, true);
            Vector2 scalar1 = new Vector2(fatness.X * 0.5f, scale.X) * lerpScalar;
            Vector2 scalar2 = new Vector2(fatness.Y * 0.5f, scale.Y) * lerpScalar;
            color *= lerpScalar;
            color2 *= lerpScalar;
            Main.EntitySpriteDraw(value, drawpos, null, color, (float)Math.PI / 2f + rotation, origin, scalar1, dir, 0f);
            Main.EntitySpriteDraw(value, drawpos, null, color, 0f + rotation, origin, scalar2, dir, 0f);
            Main.EntitySpriteDraw(value, drawpos, null, color2, (float)Math.PI / 2f + rotation, origin, scalar1 * 0.6f, dir, 0f);
            Main.EntitySpriteDraw(value, drawpos, null, color2, 0f + rotation, origin, scalar2 * 0.6f, dir, 0f);
        }
        public static void SimpleCenteredDraw(Projectile proj, string texturePath, ref Color lightColor, bool autoGlowmask = false)
        {
            Texture2D obj = (Texture2D)ModContent.Request<Texture2D>(texturePath, (AssetRequestMode)2);
            Rectangle sourceRectangle = obj.Frame(1, Main.projFrames[proj.type], 0, proj.frame, 0, 0);
            Vector2 origin = sourceRectangle.Size() / 2f;
            Color drawColor = proj.GetAlpha(lightColor);
            SpriteEffects spriteFX = proj.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
            Main.EntitySpriteDraw(obj, proj.Center - Main.screenPosition + new Vector2(0f, proj.gfxOffY), (Rectangle?)sourceRectangle, drawColor, proj.rotation, origin, proj.scale, spriteFX, 0f);
            if (autoGlowmask && ModContent.RequestIfExists(texturePath + "_Glow", out Asset<Texture2D> asset, (AssetRequestMode)2))
            {
                Main.EntitySpriteDraw((Texture2D)asset, proj.Center - Main.screenPosition + new Vector2(0f, proj.gfxOffY), (Rectangle?)sourceRectangle, Color.White * proj.Opacity, proj.rotation, origin, proj.scale, spriteFX, 0f);
            }
        }
    }
}
